﻿using AutoMapper;
using BasicInformation.ApiRead.Application.Command.Result;
using BasicInformation.Domain;
using BasicInformation.ErrorCode;
using BasicInformation.Infrastructure.Implement;
using MediatR;
using System.Text;

namespace BasicInformation.ApiRead.Application.Handler.Result
{
    public class GetResultHandler : IRequestHandler<GetResultCommand, ApiPaging<ResultModel>>
    {
        private readonly IMapper mapper;
        private readonly DatabaseContext db;
        private readonly ILogger<GetResultHandler> logger;

        public GetResultHandler(IMapper mapper, DatabaseContext db, ILogger<GetResultHandler> logger)
        {
            this.mapper = mapper;
            this.db = db;
            this.logger = logger;
        }
        public async Task<ApiPaging<ResultModel>> Handle(GetResultCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<ResultModel> result = new ApiPaging<ResultModel>();
            StringBuilder sql = new StringBuilder();
            StringBuilder countSql = new StringBuilder();

            sql.Append(@"	SELECT ResultId,ResultName FROM resultmodel ");
            var res = db.SqlSugar.Queryable<ResultModel>();
            result.Data = res.ToList();
            result.Code = ApiEnum.OK;
            result.Msg = "盘点结果查询成功";
            logger.LogInformation(result.Msg);
            return await Task.FromResult(result);

        }
    }
}